<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 * @author: Nguyen Van Nam
 * @contact: nguyennamcdt1@gmail.com
 * @license: Nam & Thien
 */
require_once 'connect.php';
$video_id = htmlentities($_POST['video_id'], ENT_QUOTES);
$video_url = htmlentities($_POST['video_url'], ENT_QUOTES);
$video_title = htmlentities($_POST['video_title'], ENT_QUOTES);
$play = htmlentities($_POST['video_bplay'], ENT_QUOTES);

if(!empty ($video_url)&& isset($video_url)){
    if(!$video_id) {
        $sql = "insert into video_manager(video_url, video_title, video_bplay) values ('$video_url','$video_title', '$play')";
        if(mysql_query($sql)) {
            return mysql_insert_id();
        } else {
            die('SQL Error!<br>'.$sql.'<br>'.mysql_error());
            return false;
        }
    }
} else {
    //update 
    $modify='';
    if(!empty ($video_url)) {
        $modify.="`video_url` = '$video_id',";            
    }
    if(!empty($video_title)) { 
        $modifs.=" `video_title` = '$video_title',"; }
    $sql = "UPDATE video_manager SET ".substr($modifs,0,-1)." WHERE video_id = $video_id";
    if(mysql_query($sql)) { 
        return $video_id;                 
    } else { 
        die("SQL Error!<br>".$sql."<br>".mysql_error()); 
        return false;                 
    }
} 
//$video_url = $_POST['video_url'];
//$video_title = $_POST['video_title'];
//$video_bplay = $_POST['video_bplay'];
//$sql_command = "insert into video_manager(video_url, video_title, video_bplay) values('{$video_url}','{$video_title}','{$video_bplay}')";
//mysql_query($sql_command) or die('Error');
//mysql_close();
//header('Location: videoManager.php');
?>
